﻿using DalatCooking.Core;
using DalatCooking.Core.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public string WriteMainMenu(int parentID)
    {
        MenuGroup group = MenuGroupManager.FindByUniqueName("mainmenu");
        var list = MenuManager.FindByParentId(parentID).Where(c => c.GroupID == group.GroupID);
        string html = "";


        html += "<ul>";
        foreach (var item in list)
        {
            html += "<li><a id=\"" + item.MenuID + "\" href=\"" + item.Url + "\">" + item.Name + "</a>";
            // Menu san pham      

            if (item.MenuID == 10)
            {
                html += BinCategory(0);
            }

            var list1 = MenuManager.FindByParentId(item.MenuID).Where(c => c.GroupID == group.GroupID);
            if (list1.Count() > 0)
                html += WriteMainMenu(item.MenuID);
            html += "</li>";
        }
        html += "</ul>";

        return html;
    }

    public string BinCategory(int parentID)
    {
        var list = CategoryManager.FindAll().Where(c => c.ParentId == parentID);
        string html = "";
        html += "<ul>";

        foreach (var item in list)
        {
            html += "<li><a href=\"/category/" + item.CategoryId + "-" + StringHelper.RemoveDiacriticsURL(item.Name) + "\">" + item.Name + "</a>";
            var list1 = CategoryManager.FindAll().Where(c => c.ParentId == item.CategoryId);
            if (list1.Count() > 0)
                html += BinCategory(item.CategoryId);

            html += "</li>";
        }
        html += "</ul>";

        return html;
    }
    public string WriteFooterMenu(int parentId)
    {
        MenuGroup group = MenuGroupManager.FindByUniqueName("mainmenu");
        var list = MenuManager.FindByGroup(group.UniqueName).Where(c=>c.ParentID== parentId);
        string html = "";
        html += "<ul>";
        foreach (var item in list)
        {
            html += "<li><a id=\"" + item.MenuID + "\" href=\"" + item.Url + "\">" + item.Name + "</a></li>";
        }
        html += "</ul>";
        return html;
    }
}
